import 'package:flutter/material.dart';

class Drawer_ extends StatefulWidget {
  const Drawer_({Key? key}) : super(key: key);

  @override
  State<Drawer_> createState() => _Drawer_State();
}

class _Drawer_State extends State<Drawer_> {
  int ye =0;
  Map i = {
    '1':Drawer(
      child: DrawerHeader(
        decoration: BoxDecoration(
            color: Colors.yellow,
            image: DecorationImage(
                image: NetworkImage('https://preview.qiantucdn.com/58pic/70/95/81/74V58PICJrJtaBJXy9n4z_origin_PIC2018.jpg!qt_w320')
            )
        ),
        child: ListTile(
          title: Text('个人中心'),
          leading: CircleAvatar(child: Icon(Icons.home),),
        ),
      ),
    ),
    '2':Drawer(
      child: Column(
        children: [
            UserAccountsDrawerHeader(
                accountName: Text('逍遥包哥'),
                accountEmail: Text('1533131461@qq.com'),
                arrowColor: Colors.white,
                currentAccountPicture: CircleAvatar(
                backgroundImage: NetworkImage("https://i1.hdslb.com/bfs/face/674e568fa04e594c234771538b995ea94b924f85.jpg@240w_240h_1c_1s_!web-avatar-nav.avif"),
                ),
                  decoration: BoxDecoration(
                  color: Colors.deepPurpleAccent,
                  image: DecorationImage(
                  image: NetworkImage('https://docs.flutter.cn/assets/images/cn/flutter-cn-logo.png'),fit: BoxFit.cover
                )
                ),
                otherAccountsPictures: [
                  Image.network('https://docs.flutter.cn/assets/images/cn/flutter-cn-logo.png'),
                  Image.network('https://docs.flutter.cn/assets/images/cn/flutter-cn-logo.png'),
                  Image.network('https://docs.flutter.cn/assets/images/cn/flutter-cn-logo.png'),
            ],
            ),
          ListTile(
            title: Text('个人中心'),
            leading: CircleAvatar(
              child: Icon(Icons.people),
            )
          ),
          Divider(),
          ListTile(
            title: Text('系统设置'),
            leading: CircleAvatar(
              child: Icon(Icons.settings),
            ),
          ),
          Divider(),
          Builder(builder:(context){
            return ListTile(
              onTap: (){
                Navigator.pushNamed(context, 'home');
              },
              title: Text('返回主页'),
              leading:CircleAvatar(
                backgroundColor: Colors.white,
                child:  Icon(Icons.home),
              ),
            );
          })
        ],
  )
    ),
  };
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        drawer: i[ye.toString()],
        appBar: AppBar(
          title: Text('Drawer'),
          backgroundColor: Colors.amber,
          actions: [
            IconButton(onPressed: (){
              setState(() {
                ye = 0;
              });
            }, icon: Icon(Icons.arrow_back))
          ],
        ),
      body: Stack(
        children: [
          Visibility(
            visible: ye==0?true:false,
            child: Column(
              children: [
                Container(
                  height:55,
                  width: MediaQuery.of(context).size.width,
                  child: OutlinedButton(
                      style:  ButtonStyle(
                          shadowColor: MaterialStateProperty.all(Color.fromRGBO(0, 0, 0, 0)),
                          backgroundColor: MaterialStateProperty.all(Colors.white),
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.zero))
                      ),
                      onPressed: (){
                        setState(() {
                          ye = 1;
                        });
                      },
                      child:Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("Drawer/DrawerHeader(抽屉菜单组件)",style:TextStyle(color: Colors.black,fontSize: 15),),
                          Icon(Icons.arrow_forward,color: Colors.black,)
                        ],
                      )
                  ),
                ),
                Container(
                  height:55,
                  width: MediaQuery.of(context).size.width,
                  child: OutlinedButton(
                      style:  ButtonStyle(
                          shadowColor: MaterialStateProperty.all(Color.fromRGBO(0, 0, 0, 0)),
                          backgroundColor: MaterialStateProperty.all(Colors.white),
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.zero))
                      ),
                      onPressed: (){
                        setState(() {
                          ye = 2;
                        });
                      },
                      child:Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("Drawer/UserAccountsDrawerHeader(用户抽屉组件)",style:TextStyle(color: Colors.black,fontSize: 15),),
                          Icon(Icons.arrow_forward,color: Colors.black,)
                        ],
                      )
                  ),
                ),
              ],
            ),
          ),
        ],
      )
    );
  }
}
